<script type="text/javascript">
    var gblfrmtData = <?php echo json_encode($frmtGroup) ;?>;
</script>
<?php

if($frmtGroup){
?>
<?php
    $tags = "<div style='margin-bottom:10px;'>";
        $tags .= "<b><u>All Properties Under $location_name</u></b>";
    $tags .= "</div>";
    
    $tags .= "<ul id='report_tree' class='filetree'>";
    foreach($frmtGroup as $key => $value){
       $group_id = $key; 
       $main_name = $value['name'];
       $item_count = $value['item_count'];  
       
       $group_types_str = '';
       
       /** group type and group sub type**/
       if (in_array("property_group_type_id", $value['fields'])) {
            $group_types = $value['group_types'];
            $group_types_str .= '<li class="closed"> <span class="folder"> Property Types </span>';
            $group_types_str .= '<ul>';
            foreach($group_types as $key_1 => $value_1){
                if(!empty($value_1['name'])){
                    $group_types_str .= "<li class='closed'>";
                    if($value_1['name'] == ''){
                        $group_types_str .= "Others &nbsp;&nbsp;=>&nbsp;&nbsp;".$value_1['count'];
                        /** Clear the Others sub type so it thus not print them**/
                        $value_1['sub_types'] = null;
                        $sub_name = "Others";
                        $title = "$main_name ($sub_name)";
                    }
                    else{
                        $tree_class_type = 'file';
                        if(isset($value_1['sub_types'])){
                            $tree_class_type = 'folder'; 
                        }
                        
                        $sub_name = $value_1['name'];
                        $title = "$main_name ($sub_name)";
                        
                        $group_types_str .= "<span class='$tree_class_type'>".$value_1['name']." &nbsp;&nbsp;(".$value_1['count'].")";  
                          $group_types_str .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                          $img = $this->Html->image('ico-15.png', array('alt'=>'List Properties','width' => '16', 'height' => '16', 'border' => '0'));
                          $group_types_str .= $this->Html->link($img, 'javascript: void(0);',array('class'=>'view_list_properties','title'=>'List Properties','style'=>'margin-top:10px;','escape'=>false));
                          $group_types_str .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                          $img = $this->Html->image('icon-16.png', array('alt'=>'Print Properties','width' => '16', 'height' => '16', 'border' => '0'));
                          $group_types_str .= $this->Html->link($img, 'javascript: void(0);',array('class'=>'print_list_properties','title'=>'Print Properties','style'=>'margin-top:10px;','escape'=>false));
                          $ids = $value_1['prp_ids'];
                          $group_types_str .= "<input type='hidden' class='prop_ids' value=$ids >";
                          $group_types_str .= "<input type='hidden' class='title' value='$title' >";
                          $group_types_str .= "<input type='hidden' class='group_id' value=$group_id >";
                        $group_types_str .= "</span>";  
                    }
                      
                       
                    if(isset($value_1['sub_types'])){
                        $group_types_str .= '<ul>';
                            //$group_types_str .= '<li> <b> Property Sub Types </b></li>';
                            $group_types_str .= '<ul>';
                        foreach($value_1['sub_types'] as $key_2 => $value_2){
                            if(!empty($value_2['name'])){
                                $title = "$main_name ($sub_name) (".$value_2['name'].")";
                                $group_types_str .= "<li>";
                                    $group_types_str .= $value_2['name']." &nbsp;&nbsp;(".$value_2['count'].")";   
                                    $group_types_str .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                                    $img = $this->Html->image('ico-15.png', array('alt'=>'List Properties','width' => '16', 'height' => '16', 'border' => '0'));
                                    $group_types_str .= $this->Html->link($img, 'javascript: void(0);',array('class'=>'view_list_properties','title'=>'List Properties','style'=>'margin-top:10px;','escape'=>false));
                                    $group_types_str .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                                    $img = $this->Html->image('icon-16.png', array('alt'=>'Print Properties','width' => '16', 'height' => '16', 'border' => '0'));
                                    $group_types_str .= $this->Html->link($img, 'javascript: void(0);',array('class'=>'print_list_properties','title'=>'Print Properties','style'=>'margin-top:10px;','escape'=>false));
                                    $ids = $value_2['prp_ids'];
                                    $group_types_str .= "<input type='hidden' class='prop_ids' value=$ids >";
                                    $group_types_str .= "<input type='hidden' class='title' value='$title' >";
                                    $group_types_str .= "<input type='hidden' class='group_id' value=$group_id >";
                                $group_types_str .= "</li>";
                            }
                        }
                            $group_types_str .= '</ul>';
                        $group_types_str .= '</ul>';
                       
                    }
                    $group_types_str .= "</li>";
                }
            }
                $group_types_str .= '</ul>';
            $group_types_str .= '</li>';
           
       }
       
       /** permit no **/
       $number_permit_str = '';
       $number_no_permit_str = '';
       if (in_array("permit_no", $value['fields'])) {
            $number_permit = $value['number_permit']['count'];
            $number_no_permit = $value['number_no_permit']['count'];
            
            $title = "$main_name (Properties With Permit)";
            $number_permit_str  = "<li>";
                $number_permit_str .= "<span class='file'>Number of Permit No. &nbsp;&nbsp; ($number_permit)";
                    $number_permit_str .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    $img = $this->Html->image('ico-15.png', array('alt'=>'List Properties','width' => '16', 'height' => '16', 'border' => '0'));
                    $number_permit_str .= $this->Html->link($img, 'javascript: void(0);',array('class'=>'view_list_properties','title'=>'List Properties','style'=>'margin-top:10px;','escape'=>false));
                    $number_permit_str .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    $img = $this->Html->image('icon-16.png', array('alt'=>'Print Properties','width' => '16', 'height' => '16', 'border' => '0'));
                    $number_permit_str .= $this->Html->link($img, 'javascript: void(0);',array('class'=>'print_list_properties','title'=>'Print Properties','style'=>'margin-top:10px;','escape'=>false));
                    $ids = $value['number_permit']['prp_ids'];
                    $number_permit_str .= "<input type='hidden' class='prop_ids' value=$ids >";
                    $number_permit_str .= "<input type='hidden' class='title' value='$title' >";
                    $number_permit_str .= "<input type='hidden' class='group_id' value=$group_id >";
                $number_permit_str .= "</span>";
            $number_permit_str .= "</li>";
            
            $title = "$main_name (Properties With Permit)";
            $number_no_permit_str  = "<li>";
                $number_no_permit_str .= "<span class='file'>Number of No Permit No. &nbsp;&nbsp; ($number_no_permit) ";
                    $number_no_permit_str .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    $img = $this->Html->image('ico-15.png', array('alt'=>'List Properties','width' => '16', 'height' => '16', 'border' => '0'));
                    $number_no_permit_str .= $this->Html->link($img, 'javascript: void(0);',array('class'=>'view_list_properties','title'=>'List Properties','style'=>'margin-top:10px;','escape'=>false));
                    $number_no_permit_str .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    $img = $this->Html->image('icon-16.png', array('alt'=>'Print Properties','width' => '16', 'height' => '16', 'border' => '0'));
                    $number_no_permit_str .= $this->Html->link($img, 'javascript: void(0);',array('class'=>'print_list_properties','title'=>'Print Properties','style'=>'margin-top:10px;','escape'=>false));
                    $ids = $value['number_no_permit']['prp_ids'];
                    $number_no_permit_str .= "<input type='hidden' class='prop_ids' value=$ids >";
                    $number_no_permit_str .= "<input type='hidden' class='title' value='$title' >";
                    $number_no_permit_str .= "<input type='hidden' class='group_id' value=$group_id >";
                $number_permit_str .= "</span>";
            $number_no_permit_str .= "</li>";
       }
       
       
       
        $tags .= "<li class='closed'>";
            $tags .= "<span class='folder'>$main_name</span>";
            $tags .= "<ul>";
                 $tags .= "<li>";
                      $tags .= "<span class='file'> Total Count ($item_count) ";
                          $tags .= "&nbsp;&nbsp;";
                          $img = $this->Html->image('ico-15.png', array('alt'=>'List Properties','width' => '16', 'height' => '16', 'border' => '0'));
                          $tags .= $this->Html->link($img, 'javascript: void(0);',array('class'=>'view_list_properties','title'=>'List Properties','style'=>'margin-top:10px;','escape'=>false));
                          $tags .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                          $img = $this->Html->image('icon-16.png', array('alt'=>'Print Properties','width' => '16', 'height' => '16', 'border' => '0'));
                          $tags .= $this->Html->link($img, 'javascript: void(0);',array('class'=>'print_list_properties','title'=>'Print Properties','style'=>'margin-top:10px;','escape'=>false));
                          $ids = $value['prp_ids'];
                          $tags .= "<input type='hidden' class='prop_ids' value=$ids >";
                          $tags .= "<input type='hidden' class='title' value='$main_name' >";
                          $tags .= "<input type='hidden' class='group_id' value=$group_id >";
                      $tags .= "</span>";
                 $tags .= "</li>";                                 
                                  
                 $tags .= $number_permit_str;
                 $tags .= $number_no_permit_str;
                 $tags .= $group_types_str;
            $tags .= "</ul>";
        $tags .= "</li>";
       
    }
     $tags .= "</ul>";
    echo $tags;
}
else{
    echo "No Report At the Moment.";
}

?>